package com.pwt.entity.base;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.pwt.annotation.Update;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.hibernate.annotations.*;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;

/**
 * @JsonIgnore  隐藏字段  好像是和  jackson  影响
 */
@MappedSuperclass
@Data
@JsonIgnoreProperties(value = { "hibernateLazyInitializer"})
@Schema
public class BaseEntity implements Serializable {

    @Id
    @GeneratedValue(generator="system_uuid")
    @GenericGenerator(name="system_uuid",strategy="uuid")
    @Column(name = "id")
    @Schema(description = "ID")
    @NotBlank(groups = Update.class,message = "修改时必传")
    protected String id;

    @Column(name = "status")
    @Schema(description = "状态,0:关闭,1:开启",hidden = true)
    protected Integer status;

    @Column(name = "create_time",updatable = false)
    @CreationTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @Hidden
    protected Date createTime;

    @Column(name = "update_time",updatable = true)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @UpdateTimestamp
    @JsonIgnore
    protected Date updateTime;

    @Column(name = "create_by")
    @Schema(hidden = true)
    @JsonIgnore
    protected String createBy;

    @Column(name = "update_by")
    @Schema(hidden = true)
    @JsonIgnore
    protected String updateBy;

    @Schema(hidden = true)
    @Column(name = "deleted")
    @JsonIgnore
    protected Integer deleted;
}